package com.itheima.service.impl;


import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    DeptMapper deptMapper;

    @Override
    public List<Dept> findAllTo() {
        return deptMapper.findAll();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public Integer delete(Integer id) {
        Integer i= deptMapper.delete(id);
        return i;
    }

    /**
     * 新增
     * @param dept
     */
    @Override
    public Integer add(Dept dept) {
        //补全基础属性（因为这些数据不应该由客户端生成 而是由后端生成）
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        //保存部门
        return deptMapper.insert(dept);
    }

    @Override
    public Dept getById(Integer id) {
        return deptMapper.getById(id);
    }

    @Override
    public Integer update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        return deptMapper.update(dept);
    }
}
